import React, { useEffect } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'

function UseAuth({ children }) {
    function Use() {
        let token = localStorage.getItem('token')
        let { pathname } = useLocation('')
        let Navigate = useNavigate()
        let WhileList = ['/login']
        useEffect(() => {
            if (!token && !WhileList.includes(pathname)) {
                Navigate('/login')
            }
        },[])
        return children
    }
    return <Use></Use>
}

export default UseAuth
// import React from 'react'
// import { Navigate } from 'react-router-dom'

// function useAuth(Com) {
//     let token = localStorage.getItem('token')
//     if(token){
//         return <Com></Com>
//     }
//     else{
//         Navigate('/')
//     }
//   return (
//     <div>
      
//     </div>
//   )
// }

// export default useAuth
